<template>
	<view class="container">
		<div class="box" v-for="(item,index) in noticeList" :key="index" @click="itemHandle(item)">
			<div class="row" data-flex>
				<div class="avatar">
					<image :src="item.photo" mode=""></image>
				</div>
				<div data-flex-box="1">
					<div class="name">{{item.loginName}}</div>
					<div class="time">{{item.createDate | fnContentTime}}</div>
				</div>
			</div>
			<div class="row">
				<div class="content">
					{{item.title}}
				</div>
			</div>
		</div>
		<view class="tips" v-show="noticeList.length === 0">
			当前没有最新动态哦
		</view>
	</view>
</template>

<script>
import Api from '@/common/api';
export default {
	name: 'notice',
    data() {
        return {
            // 公告数据
            noticeList: [],
			pageNo: 1,
			pageSize: 10
        }
    },
    filters: {
        fnContentTime(_date) {
			_date = Number(_date);
            var date = _date ? new Date(_date) : new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            var hour = date.getHours();
            var minute = date.getMinutes();
            var second = date.getSeconds();
            return [year, month, day].map(function(n) {
                    n = n.toString();return n[1] ? n : '0' + n
                }).join('-') + ' ' + [hour, minute].map(function(n) {
                    n = n.toString();return n[1] ? n : '0' + n
                }).join(':')
        }
    },
    created() {
        this.getNoticeList('headerRefreshing');
    },
    methods: {
        // 动态列表
        async getNoticeList(sign) {
			if(sign == 'headerRefreshing') {
				this.pageNo = 1;
			} else {
				this.pageNo ++;
			}
            var params = {
                'informationType': 4,
				'pageNo': this.pageNo,
				'pageSize': this.pageSize
            };
            var data = await Api.APPCall('get', Api.index.noticeList, params);
			if(this.pageNo == 1) {
				this.noticeList = [];
			}
			this.noticeList = this.noticeList.concat(data.listData);
        },
		// 点击动态
		itemHandle(item) {
			// 路径
			var url = '/pages/langwen/richtxtDetail';
			// 参数 
			var param = {
			    id: item.id
			};
			uni.navigateTo({
			    url: `${url}?param=${encodeURIComponent(JSON.stringify(param))}`
			});
		}
    }
}
</script>

<style lang="css">
page {
	background: rgba(245, 245, 245, 1);
}

.box {
	background:rgba(255,255,255,1);
	overflow: hidden;
	margin: 15px;
	box-shadow:0px 1px 8px 0px rgba(0,0,0,0.02);
	border-radius:10px;
}

.row {
	margin: 10px;
}

.avatar {
	width: 39px;
	height: 39px;
	border-radius: 50%;
	margin-right: 10px;
}

.name {
	font-size:14px;
	font-weight:400;
	color:rgba(51,51,51,1);
}

.time {
	font-size:12px;
	font-weight:400;
	color:rgba(191,191,191,1);
}

.content {
	font-size:13px;
	font-weight:400;
	color:rgba(119,119,119,1);
	line-height:21px;
}

.image {
	height: 200px;
	border-radius: 8px;
	overflow: hidden;
}

.tips {
	padding-top: 160rpx;
	text-align: center;
	font-size: 28rpx;
}
</style>
